<?php
	$distribute = new Distribute($minfo['member_id']);
	$disconfig = (object)Distribute::$config;
?>
<script>
	var self_level = '<?php echo $distribute->getLevel()?>';
	var show_level = '<?php echo $_GET['level']?>';
	if(self_level > show_level) {
		layer.msg("不能查看比自己更大的等级！", function () {
			history.back()
		});
	}
</script>

<style>
	#box{
		padding: 15px;
		box-sizing: border-box;
	}
	th,td{
		text-align: center;
	}
	thead,tr{
		border-bottom: 1px dashed #ddd;
		line-height: 40px;
	}
	.btn{
		display: inline-block;
		width : 26%;
		margin-left: 2%;
		margin-right: 2%;
		text-align: center;
		line-height: 30px;
		border-radius : 5px;
		background: black;
		color: #fff !important;
		margin-bottom: 40px;
	}
	.btn.red{
		background: red;
	}
	.btn.blue{
		background: blue;
	}
	.btn.green{
		background: green;
	}
</style>
<div id="box">
	<a href="/wap/tmpl/member/distribute_center.php?action=show_member&level=<?php echo $_GET['level']?>" class="btn red">查看所有</a>
	<a href="/wap/tmpl/member/distribute_center.php?action=show_member&level=<?php echo $_GET['level']?>&show_buyer=1" class="btn green">查看买家</a>
	<a href="/wap/tmpl/member/distribute_center.php?action=show_member&level=<?php echo $_GET['level']?>&show_proxy=1" class="btn blue">查看代理</a>

<table width="100%">
	<thead>
		<th>用户名</th>
	
		<th>会员类型</th>
		<th>分销时间</th>
		<th>累计佣金(元)</th>
	</thead>
<?php
$members = $distribute->getLevelMember($_GET['level']);
	foreach ($members as $key => $member) {
		if (isset($_GET['show_buyer'])) {
			if ($member['is_buyer'] != 1) {
				unset($members[$key]);
			}
		}
		else if (isset($_GET['show_proxy'])) {
			if ($member['is_buyer'] == 1) {
				unset($members[$key]);
			}
		}
	}
foreach ($members as $member){
	 	$_minfo = ml('member')->find($member['member_id']);
		if(!$_minfo){
			continue;
		}
?>
		<tr>
			<td>
				<?php
				echo $_minfo['member_name'];
				?>
			</td>
		
			<td>
				<?php
				echo $member['is_buyer'] == 1 ? '买家' : '代理';
				?>
			</td>
			<td>
				<?php
				echo date('Y-m-d', $member['time']);
				?>
			</td>
			<td style="color:red;">
				<?php
				$res = ml()->query("select ifnull(sum(margin),0) as margin from ra_weproxy_order_margin where member_id = $minfo[member_id] and from_member = {$member['member_id']}");
				echo $res[0]['margin'];
				?>
			</td>
		</tr>
<?php
}
?>
</table>
</div>
